<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/pages/stock_manage/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <base href="<%= basePath %>"/>
    <title>出库管理</title>
    <style>
        body {
            margin: 0;
            font-family: 'Segoe UI', 'Arial', sans-serif;
            background: #f5f6fa;
        }

        .header {
            background: #4f8cff;
            color: #fff;
            padding: 24px 0 18px 0;
            text-align: center;
            font-size: 2rem;
            font-weight: bold;
            letter-spacing: 2px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
        }

        .container {
            max-width: 1200px;
            margin: 30px auto;
            padding: 0 20px;
        }

        .filter-form {
            margin-bottom: 20px;
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            align-items: end;
            background: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
        }

        .filter-form .form-group {
            margin-bottom: 0;
        }

        .filter-form label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #333;
        }

        .filter-form input, .filter-form select {
            padding: 10px 12px;
            border: 1px solid #dcdde1;
            border-radius: 6px;
            font-size: 14px;
            transition: border-color 0.3s;
        }

        .filter-form input:focus, .filter-form select:focus {
            outline: none;
            border-color: #4f8cff;
            box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.2);
        }

        .filter-form input[type="submit"], .filter-form input[type="button"] {
            background-color: #4f8cff;
            color: white;
            border: none;
            cursor: pointer;
            font-weight: 500;
            padding: 10px 20px;
            transition: background-color 0.3s;
        }

        .filter-form input[type="submit"]:hover, .filter-form input[type="button"]:hover {
            background-color: #3a7bff;
        }

        .filter-form input[type="button"] {
            background-color: #6c757d;
        }

        .filter-form input[type="button"]:hover {
            background-color: #5a6268;
        }

        /* 固定下拉框宽度 */
        .status-select {
            width: 160px;
            box-sizing: border-box;
        }

        .order-code-input {
            width: 200px;
        }

        .product-list {
            width: 100%;
            border-collapse: collapse;
            table-layout: fixed;
            background: #fff;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
        }

        .product-list th, .product-list td {
            border: 1px solid #eee;
            padding: 14px 12px;
            text-align: left;
            word-wrap: break-word;
        }

        .product-list th {
            background-color: #f8f9fc;
            font-weight: 600;
            color: #4a5568;
            text-transform: uppercase;
            font-size: 13px;
            letter-spacing: 0.5px;
        }

        .product-list tbody tr {
            transition: background-color 0.2s;
        }

        .product-list tbody tr:hover {
            background-color: #f8faff;
        }

        /* 为每列设置固定宽度 */
        .product-list .code-col {
            width: 20%;
        }

        .product-list .user-col {
            width: 20%;
        }

        .product-list .time-col {
            width: 20%;
        }

        .product-list .quantity-col {
            width: 15%;
        }

        .product-list .action-col {
            width: 25%;
        }

        .detail-modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.5);
            backdrop-filter: blur(2px);
        }

        .detail-content {
            background-color: #fff;
            margin: 5% auto;
            padding: 30px;
            border-radius: 8px;
            width: 80%;
            max-width: 1000px;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
            animation: modalopen 0.3s ease-out;
            max-height: 80vh;
            overflow-y: auto;
        }

        @keyframes modalopen {
            from {
                opacity: 0;
                transform: translateY(-60px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
            line-height: 1;
            cursor: pointer;
            transition: color 0.2s;
        }

        .close:hover,
        .close:focus {
            color: #333;
        }

        /* 查询结果为空时的样式 */
        .no-results {
            text-align: center;
            padding: 40px;
            color: #718096;
            font-size: 16px;
        }

        .no-results:before {
            content: "😔";
            display: block;
            font-size: 48px;
            margin-bottom: 15px;
        }

        /* 加载状态样式 */
        .loading {
            text-align: center;
            padding: 40px;
            color: #4f8cff;
        }

        .loading:after {
            content: " ";
            display: inline-block;
            width: 20px;
            height: 20px;
            margin: 0 10px;
            border-radius: 50%;
            border: 3px solid #4f8cff;
            border-color: #4f8cff transparent #4f8cff transparent;
            animation: loading 1.2s linear infinite;
        }

        @keyframes loading {
            0% {
                transform: rotate(0deg);
            }
            100% {
                transform: rotate(360deg);
            }
        }

        /* 按钮样式 */
        .btn {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-right: 5px;
            font-size: 13px;
            transition: background-color 0.2s;
        }

        .btn-primary {
            background-color: #4f8cff;
            color: white;
        }

        .btn-primary:hover {
            background-color: #3a7bff;
        }

        .btn-success {
            background-color: #28a745;
            color: white;
        }

        .btn-success:hover {
            background-color: #218838;
        }

        .btn-danger {
            background-color: #dc3545;
            color: white;
        }

        .btn-danger:hover {
            background-color: #c82333;
        }

        .btn-warning {
            background-color: #ffc107;
            color: black;
        }

        .btn-warning:hover {
            background-color: #e0a800;
        }

        .btn:disabled {
            background-color: #cccccc;
            cursor: not-allowed;
        }

        /* 订单状态样式 */
        .status-pending {
            color: #ffc107;
            font-weight: bold;
        }

        .status-completed {
            color: #28a745;
            font-weight: bold;
        }

        .status-cancelled {
            color: #dc3545;
            font-weight: bold;
        }

        /* 支付状态样式 */
        .payment-unpaid {
            color: #dc3545;
        }

        .payment-paid {
            color: #28a745;
        }

        /* 详情表格样式 */
        .detail-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 15px;
        }

        .detail-table th, .detail-table td {
            border: 1px solid #ddd;
            padding: 12px;
            text-align: left;
        }

        .detail-table th {
            background-color: #f2f2f2;
        }

        .detail-title {
            margin-top: 0;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
            color: #333;
        }

        /* 美化分页样式 */
        .pagination-wrapper {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 25px;
            padding: 20px;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
        }

        .pagination-info {
            color: #4a5568;
            font-size: 14px;
        }

        .pagination {
            display: flex;
            align-items: center;
            list-style: none;
        }

        .pagination li {
            margin: 0 3px;
        }

        .pagination a, .pagination span {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 36px;
            height: 36px;
            border-radius: 6px;
            text-decoration: none;
            color: #4a5568;
            font-weight: 500;
            transition: all 0.2s ease-in-out;
            border: 1px solid transparent;
        }

        .pagination a:hover {
            background-color: #edf2f7;
            color: #4f8cff;
        }

        .pagination .active span {
            background-color: #4f8cff;
            color: white;
            border-color: #4f8cff;
        }

        .pagination .disabled a {
            color: #cbd5e0;
            cursor: not-allowed;
        }

        .pagination .disabled a:hover {
            background-color: transparent;
            color: #cbd5e0;
        }

        .pagination .prev-next a {
            width: auto;
            padding: 0 14px;
        }

        .pagination .prev-next a:hover {
            background-color: #edf2f7;
        }

        .pagination .prev-next.active a {
            background-color: #4f8cff;
            color: white;
        }

        .pagination .prev-next.active a:hover {
            background-color: #3a7bff;
        }

        .pagination-jump {
            display: flex;
            align-items: center;
            color: #4a5568;
            font-size: 14px;
        }

        .pagination-jump input {
            width: 50px;
            padding: 8px;
            margin: 0 8px;
            border: 1px solid #dcdde1;
            border-radius: 4px;
            text-align: center;
            transition: border-color 0.3s;
        }

        .pagination-jump input:focus {
            outline: none;
            border-color: #4f8cff;
            box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.2);
        }

        .pagination-jump button {
            padding: 8px 14px;
            background-color: #4f8cff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.2s;
            margin-left: 8px;
        }

        .pagination-jump button:hover {
            background-color: #3a7bff;
        }

        /* 固定表格容器高度，防止页面晃动 */
        .table-container {
            min-height: 400px;
            position: relative;
        }

        /* 固定分页容器高度，防止页面晃动 */
        .pagination-container {
            min-height: 80px;
        }
    </style>
    <script>
        // 分页相关的变量
        var currentPage = 1;
        var pageSize = 5;
        var totalPage = 1;
        var totalCount = 0;

        // 当前筛选条件
        var currentStatus = 'pending';
        var currentOrderCode = '';

        // 页面加载完成后获取订单数据
        window.onload = function() {
            loadOrders('pending', ''); // 默认加载待发货订单
        }

        // 加载订单数据
        function loadOrders(status, orderCode) {
            showLoading();

            // 保存当前筛选条件
            currentStatus = status;
            currentOrderCode = orderCode;

            var xhr = new XMLHttpRequest();
            xhr.open("GET", "StockOutServlet?action=getOrders&status=" + status + "&orderCode=" + encodeURIComponent(orderCode) +
                "&currentPage=" + currentPage + "&pageSize=" + pageSize, true);
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    try {
                        var response = JSON.parse(xhr.responseText);
                        if (response.code === 200) {
                            var data = response.data || {};
                            var orders = data.results || [];
                            totalCount = data.totalCount || 0;
                            totalPage = data.totalPage || 1;
                            currentPage = data.currentPage || 1;

                            displayOrders(orders, status);
                            updatePagination(); // 更新分页控件
                        } else {
                            showError("加载订单失败: " + response.msg);
                        }
                    } catch (e) {
                        console.error("解析订单数据出错:", e);
                        showError("数据解析错误");
                    }
                }
            };
            xhr.send();
        }

        // 显示加载状态
        function showLoading() {
            var tbody = document.querySelector("#productList tbody");
            tbody.innerHTML = '<tr><td colspan="5"><div class="loading"></div></td></tr>';
        }

        // 显示错误信息
        function showError(message) {
            var tbody = document.querySelector("#productList tbody");
            tbody.innerHTML = '<tr><td colspan="5"><div class="no-results">错误：' + message + '</div></td></tr>';
        }

        // 显示订单列表
        function displayOrders(orders, status) {
            var tbody = document.querySelector("#productList tbody");
            tbody.innerHTML = ""; // 清空现有内容

            if (!orders || orders.length === 0) {
                var row = tbody.insertRow();
                var cell = row.insertCell(0);
                cell.colSpan = 5;
                cell.textContent = status === 'pending' ? "暂无待发货订单" : "暂无已发货订单";
                cell.className = "no-results";
                return;
            }

            for (var i = 0; i < orders.length; i++) {
                var order = orders[i];
                var row = tbody.insertRow();

                var codeCell = row.insertCell(0);
                codeCell.textContent = order.code;
                codeCell.className = "code-col";

                var userCell = row.insertCell(1);
                userCell.textContent = order.userName || "";
                userCell.className = "user-col";

                var timeCell = row.insertCell(2);
                timeCell.textContent = order.orderTime || "";
                timeCell.className = "time-col";

                var amountCell = row.insertCell(3);
                amountCell.textContent = "¥" + (order.totalAmount || "0.00");
                amountCell.className = "quantity-col";

                var actionCell = row.insertCell(4);
                actionCell.className = "action-col";

                // 根据订单状态显示不同的操作按钮
                if (status === 'pending') {
                    // 待发货订单
                    actionCell.innerHTML =
                        '<button class="btn btn-success" onclick="completeOutbound(' + order.id + ')">一键发货</button>' +
                        '<button class="btn btn-warning" onclick="showOrderDetails(' + order.id + ')">详情</button>' +
                        '<button class="btn btn-danger" onclick="cancelOutbound(' + order.id + ')">取消</button>';
                } else {
                    // 已发货订单
                    actionCell.innerHTML =
                        '<button class="btn btn-warning" onclick="showOrderDetails(' + order.id + ')">详情</button>' +
                        '<button class="btn btn-danger" onclick="deleteOutbound(' + order.id + ')">删除</button>';
                }
            }
        }

        // 处理表单提交（切换状态）
        function submitForm(event) {
            event.preventDefault(); // 阻止表单默认提交行为

            var status = document.getElementById("status").value;
            var orderCode = document.getElementById("orderCode").value;
            currentPage = 1; // 重置为第一页
            loadOrders(status, orderCode);
        }

        // 重置查询条件
        function resetForm() {
            document.getElementById("orderCode").value = "";
            var status = document.getElementById("status").value;
            currentPage = 1; // 重置为第一页
            loadOrders(status, "");
        }

        // 显示订单详情
        function showOrderDetails(orderId) {
            // 显示加载状态
            var modalContent = document.getElementById('modalContent');
            modalContent.innerHTML = '<span class="close" onclick="closeDetailModal()">&times;</span>' +
                '<h2 class="detail-title">订单详情</h2>' +
                '<div class="loading"></div>';
            document.getElementById('detailModal').style.display = 'block';

            // 发送 AJAX 请求获取订单详情
            var xhr = new XMLHttpRequest();
            xhr.open("GET", "StockOutServlet?action=getOrderDetails&orderId=" + orderId, true);
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    try {
                        var response = JSON.parse(xhr.responseText);
                        if (response.code === 200) {
                            displayOrderDetails(response.data, orderId);
                        } else {
                            modalContent.innerHTML = '<span class="close" onclick="closeDetailModal()">&times;</span>' +
                                '<h2 class="detail-title">订单详情</h2>' +
                                '<div class="no-results"><p>加载失败: ' + response.msg + '</p></div>';
                        }
                    } catch (e) {
                        console.error("解析订单详情数据出错:", e);
                        modalContent.innerHTML = '<span class="close" onclick="closeDetailModal()">&times;</span>' +
                            '<h2 class="detail-title">订单详情</h2>' +
                            '<div class="no-results"><p>数据解析错误</p></div>';
                    }
                }
            };
            xhr.send();
        }

        // 显示订单详情内容
        function displayOrderDetails(details, orderId) {
            var modalContent = document.getElementById('modalContent');
            var html = '<span class="close" onclick="closeDetailModal()">&times;</span>' +
                '<h2 class="detail-title">订单详情 (订单ID: ' + orderId + ')</h2>';

            if (!details || details.length === 0) {
                html += '<div class="no-results"><p>该订单没有详情信息</p></div>';
                modalContent.innerHTML = html;
                return;
            }

            html += '<table class="detail-table">' +
                '<thead>' +
                '<tr>' +
                '<th>产品名称</th>' +
                '<th>产品数量</th>' +
                '<th>单价</th>' +
                '<th>小计</th>' +
                '</tr>' +
                '</thead>' +
                '<tbody>';

            var total = 0;

            // 遍历所有详情项
            for (var i = 0; i < details.length; i++) {
                var detail = details[i];
                var subtotal = (detail.proquantity || 0) * (detail.unitprice || 0);
                total += subtotal;

                html += '<tr>' +
                    '<td>' + (detail.proname || '未知产品') + '</td>' +
                    '<td>' + (detail.proquantity || 0) + '</td>' +
                    '<td>¥' + (detail.unitprice || '0.00') + '</td>' +
                    '<td>¥' + subtotal.toFixed(2) + '</td>' +
                    '</tr>';
            }

            html += '<tr>' +
                '<th colspan="3" style="text-align: right;">总计:</th>' +
                '<td>¥' + total.toFixed(2) + '</td>' +
                '</tr>' +
                '</tbody>' +
                '</table>';

            modalContent.innerHTML = html;
        }

        // 关闭详情弹窗
        function closeDetailModal() {
            document.getElementById('detailModal').style.display = 'none';
        }

        // 一键发货
        function completeOutbound(orderId) {
            if (!confirm("确定要将此订单一键发货吗？发货后将减少相应产品的库存数量。")) {
                return;
            }

            var xhr = new XMLHttpRequest();
            xhr.open("POST", "StockOutServlet", true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    try {
                        var response = JSON.parse(xhr.responseText);
                        if (response.code === 200) {
                            alert("发货成功！");
                            // 重新加载当前状态的订单列表
                            loadOrders(currentStatus, currentOrderCode);
                        } else {
                            alert("发货失败: " + response.msg);
                        }
                    } catch (e) {
                        console.error("解析发货结果出错:", e);
                        alert("发货操作失败");
                    }
                }
            };
            xhr.send("action=completeOutbound&orderId=" + orderId);
        }

        // 取消发货
        function cancelOutbound(orderId) {
            if (!confirm("确定要取消此发货订单吗？")) {
                return;
            }

            var xhr = new XMLHttpRequest();
            xhr.open("POST", "StockOutServlet", true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    try {
                        var response = JSON.parse(xhr.responseText);
                        if (response.code === 200) {
                            alert("订单已取消！");
                            // 重新加载当前状态的订单列表
                            loadOrders(currentStatus, currentOrderCode);
                        } else {
                            alert("取消订单失败: " + response.msg);
                        }
                    } catch (e) {
                        console.error("解析取消订单结果出错:", e);
                        alert("取消订单操作失败");
                    }
                }
            };
            xhr.send("action=cancelOutbound&orderId=" + orderId);
        }

        // 删除发货订单
        function deleteOutbound(orderId) {
            if (!confirm("确定要删除此发货订单吗？此操作不可恢复！")) {
                return;
            }

            var xhr = new XMLHttpRequest();
            xhr.open("POST", "StockOutServlet", true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    try {
                        var response = JSON.parse(xhr.responseText);
                        if (response.code === 200) {
                            alert("订单已删除！");
                            // 重新加载当前状态的订单列表
                            loadOrders(currentStatus, currentOrderCode);
                        } else {
                            alert("删除订单失败: " + response.msg);
                        }
                    } catch (e) {
                        console.error("解析删除订单结果出错:", e);
                        alert("删除订单操作失败");
                    }
                }
            };
            xhr.send("action=deleteOutbound&orderId=" + orderId);
        }

        // 点击弹窗外部关闭弹窗
        window.onclick = function(event) {
            var modal = document.getElementById('detailModal');
            if (event.target == modal) {
                closeDetailModal();
            }
        }

        // 更新分页控件
        function updatePagination() {
            // 更新分页信息
            document.querySelector(".pagination-info").textContent =
                "共" + totalCount + "条记录,当前第" + currentPage + "/" + totalPage + "页";

            // 更新分页按钮
            updatePaginationButtons();

            // 更新跳转输入框
            var jumpInput = document.querySelector(".pagination-jump input");
            jumpInput.max = totalPage;
            jumpInput.value = currentPage;
        }

        // 更新分页按钮
        function updatePaginationButtons() {
            var paginationUl = document.querySelector(".pagination");
            paginationUl.innerHTML = "";

            // 上一页
            var prevLi = document.createElement("li");
            prevLi.className = "prev-next " + (currentPage <= 1 ? "disabled" : "");
            var prevLink = document.createElement("a");
            prevLink.href = "#";
            prevLink.innerHTML = "&laquo; 上一页";
            prevLink.onclick = function(e) {
                e.preventDefault();
                if (currentPage > 1) {
                    currentPage--;
                    loadOrders(currentStatus, currentOrderCode);
                }
            };
            prevLi.appendChild(prevLink);
            paginationUl.appendChild(prevLi);

            // 页码
            var startPage = Math.max(1, currentPage - 2);
            var endPage = Math.min(totalPage, currentPage + 2);

            // 确保显示5个页码按钮
            if (endPage - startPage < 4) {
                if (startPage === 1) {
                    endPage = Math.min(totalPage, startPage + 4);
                } else {
                    startPage = Math.max(1, endPage - 4);
                }
            }

            // 第一页
            if (startPage > 1) {
                var firstLi = document.createElement("li");
                var firstLink = document.createElement("a");
                firstLink.href = "#";
                firstLink.textContent = "1";
                firstLink.onclick = function(e) {
                    e.preventDefault();
                    currentPage = 1;
                    loadOrders(currentStatus, currentOrderCode);
                };
                firstLi.appendChild(firstLink);
                paginationUl.appendChild(firstLi);

                // 省略号
                if (startPage > 2) {
                    var ellipsisLi = document.createElement("li");
                    ellipsisLi.textContent = "...";
                    paginationUl.appendChild(ellipsisLi);
                }
            }

            // 中间页码
            for (var i = startPage; i <= endPage; i++) {
                var pageLi = document.createElement("li");
                if (i === currentPage) {
                    pageLi.className = "active";
                    var pageSpan = document.createElement("span");
                    pageSpan.textContent = i;
                    pageLi.appendChild(pageSpan);
                } else {
                    var pageLink = document.createElement("a");
                    pageLink.href = "#";
                    pageLink.textContent = i;
                    pageLink.onclick = (function(page) {
                        return function(e) {
                            e.preventDefault();
                            currentPage = page;
                            loadOrders(currentStatus, currentOrderCode);
                        };
                    })(i);
                    pageLi.appendChild(pageLink);
                }
                paginationUl.appendChild(pageLi);
            }

            // 最后一页
            if (endPage < totalPage) {
                // 省略号
                if (endPage < totalPage - 1) {
                    var ellipsisLi = document.createElement("li");
                    ellipsisLi.textContent = "...";
                    paginationUl.appendChild(ellipsisLi);
                }

                var lastLi = document.createElement("li");
                var lastLink = document.createElement("a");
                lastLink.href = "#";
                lastLink.textContent = totalPage;
                lastLink.onclick = function(e) {
                    e.preventDefault();
                    currentPage = totalPage;
                    loadOrders(currentStatus, currentOrderCode);
                };
                lastLi.appendChild(lastLink);
                paginationUl.appendChild(lastLi);
            }

            // 下一页
            var nextLi = document.createElement("li");
            nextLi.className = "prev-next " + (currentPage >= totalPage ? "disabled" : "");
            var nextLink = document.createElement("a");
            nextLink.href = "#";
            nextLink.innerHTML = "下一页 &raquo;";
            nextLink.onclick = function(e) {
                e.preventDefault();
                if (currentPage < totalPage) {
                    currentPage++;
                    loadOrders(currentStatus, currentOrderCode);
                }
            };
            nextLi.appendChild(nextLink);
            paginationUl.appendChild(nextLi);
        }

        // 跳转到指定页
        function jumpToPage() {
            var jumpInput = document.querySelector(".pagination-jump input");
            var page = parseInt(jumpInput.value);
            if (page >= 1 && page <= totalPage) {
                currentPage = page;
                loadOrders(currentStatus, currentOrderCode);
            } else {
                alert(`请输入有效的页码 (1-${totalPage})`);
                jumpInput.focus();
            }
        }

        // 绑定回车事件
        document.addEventListener('DOMContentLoaded', function() {
            var jumpInput = document.querySelector(".pagination-jump input");
            jumpInput.addEventListener('keyup', function(e) {
                if (e.key === 'Enter') {
                    jumpToPage();
                }
            });
        });
    </script>
</head>
<body>
<div class="header">出库管理</div>

<div class="container">
    <!-- 筛选条件区域 -->
    <form class="filter-form" onsubmit="submitForm(event)">
        <div class="form-group">
            <label for="status">订单状态：</label>
            <select id="status" name="status" class="status-select">
                <option value="pending">待发货</option>
                <option value="completed">已发货</option>
            </select>
        </div>

        <div class="form-group">
            <label for="orderCode">订单编号：</label>
            <input type="text" id="orderCode" name="orderCode" class="order-code-input" placeholder="输入订单编号进行模糊查询">
        </div>

        <div class="form-group">
            <input type="submit" value="查询" class="btn btn-primary">
            <input type="button" value="重置" class="btn" onclick="resetForm()">
        </div>
    </form>
    <!-- 出库订单列表 -->
    <div class="table-container">
        <table class="product-list" id="productList">
            <thead>
            <tr>
                <th class="code-col">订单编号</th>
                <th class="user-col">用户</th>
                <th class="time-col">订单时间</th>
                <th class="quantity-col">订单金额</th>
                <th class="action-col">操作</th>
            </tr>
            </thead>
            <tbody>
            <tr><td colspan="5" class="loading"></td></tr>
            </tbody>
        </table>
    </div>

    <!-- 分页控件 -->
    <div class="pagination-container">
        <div class="pagination-wrapper">
            <div class="pagination-info">共 0 条记录，当前第 1/1 页</div>
            <ul class="pagination">
                <li class="prev-next disabled"><a href="#">&laquo; 上一页</a></li>
                <li class="active"><span>1</span></li>
                <li class="prev-next disabled"><a href="#">下一页 &raquo;</a></li>
            </ul>
            <div class="pagination-jump">
                跳转到 <input type="number" min="1" max="1" value="1"> 页
                <button onclick="jumpToPage()">确定</button>
            </div>
        </div>
    </div>
</div>

<!-- 订单详情弹窗 -->
<div id="detailModal" class="detail-modal">
    <div class="detail-content">
        <div id="modalContent">
            <!-- 动态加载详细信息 -->
        </div>
    </div>
</div>

</body>
</html>
